﻿using NDF.Web.Mvc.UI;
using NDF.Web.Mvc.UI.EasyUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace System.Web.Mvc
{
    public static class My97Extensions
    {
        public static MvcHtmlString My97(this EasyUiFactory factory, string name)
        {
            return My97Helper(factory, null, name, null, null, null);
        }

        public static MvcHtmlString My97(this EasyUiFactory factory, string name, object value)
        {
            return My97Helper(factory, null, name, value, null, null);
        }

        public static MvcHtmlString My97(this EasyUiFactory factory, string name, object value, object dataOptions)
        {
            return My97Helper(factory, null, name, value, dataOptions, null);
        }

        public static MvcHtmlString My97(this EasyUiFactory factory, string name, object value, object dataOptions, object htmlAttributes)
        {
            return My97Helper(factory, null, name, value, dataOptions, htmlAttributes);
        }




        public static MvcHtmlString My97For<TModel, TProperty>(this EasyUiFactory<TModel> factory, Expression<Func<TModel, TProperty>> expression)
        {
            return My97For(factory, expression, null, null);
        }

        public static MvcHtmlString My97For<TModel, TProperty>(this EasyUiFactory<TModel> factory, Expression<Func<TModel, TProperty>> expression, object dataOptions)
        {
            return My97For(factory, expression, dataOptions, null);
        }

        public static MvcHtmlString My97For<TModel, TProperty>(this EasyUiFactory<TModel> factory, Expression<Func<TModel, TProperty>> expression, object dataOptions, object htmlAttributes)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, factory.Html.ViewData);
            string name = ExpressionHelper.GetExpressionText(expression);
            return My97Helper(factory,
                                     metadata,
                                     name,
                                     metadata.Model,
                                     dataOptions,
                                     htmlAttributes);
        }


        private static MvcHtmlString My97Helper(this EasyUiFactory factory, ModelMetadata metadata, string name, object value, object dataOptions, object htmlAttributes)
        {
            return factory.EasyUiHelper(EasyUiType.My97, metadata, name, value, false, dataOptions, htmlAttributes);
        }
    }
}
